<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">

<head>
    <meta charset="UTF-8">
    <title>站点任务</title>
    <link href="__PUBLIC__/layui/css/layui.css" rel="stylesheet" />
    <link rel="stylesheet" href="__PUBLIC__/css/global.css" media="all">
    <link href="__PUBLIC__/Font-Awesome/css/font-awesome.css" rel="stylesheet" />
</head>

<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote">
        <form  class="layui-form" action="">
            <div class="custom-form-item">
                <label class="layui-form-label">站点列表：</label>
                <div class="layui-input-inline">
                    <select name="site">
                        <option value="">站点列表</option>
                        <volist name="sitedao" id="site">
                            <option value="{$site.site_id}" <if condition="$_GET['site'] eq $site['site_id']">selected</if> >{$site.site_name}(<if condition="$site['site_status'] eq 1">开启<else/>关闭</if>)</option>
                        </volist>
                    </select>
                </div>
            </div>
            <div class="custom-form-item">
                <label class="layui-form-label">商品状态：</label>
                <div class="layui-input-inline">
                    <select name="status">
                        <option value="">任务状态</option>
                        <option value="1" <if condition="$_GET['status'] eq 1">selected</if>>开启</option>
                        <option value="2" <if condition="$_GET['status'] eq 2">selected</if>>关闭</option>
                    </select>
                </div>
            </div>
            <div class="custom-form-item">
                <label class="layui-form-label">任务状态：</label>
                <div class="layui-input-inline">
                    <select name="teamstatus">
                        <option value="">团队任务状态 </option><!--1:正常 2：结束 3：删除 4：抢购中-->
                        <option value="1" <if condition="$_GET['teamstatus'] eq 1">selected</if>>排队抢购中</option>
                        <option value="2" <if condition="$_GET['teamstatus'] eq 2">selected</if>>结束</option>
                        <option value="3" <if condition="$_GET['teamstatus'] eq 3">selected</if>>删除</option>
                        <option value="4" <if condition="$_GET['teamstatus'] eq 4">selected</if>>抢购中</option>
                    </select>
                </div>
            </div>
            <div class="custom-form-item">
                <label class="layui-form-label">团队名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="teamname" maxlength="20" placeholder="团队名称匹配" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="custom-form-item">
                <button class="layui-btn search" lay-submit lay-filter="search">搜索</button>
            </div>
            <div class="layui-clear"></div>
        </form>
    </blockquote>
   <!-- <blockquote class="layui-elem-quote">
        <button  class="layui-btn layui-btn-small add">
            <i class="layui-icon">&#xe608;</i> 创建团队任务
        </button>
    </blockquote>-->
    <fieldset class="layui-elem-field">
        <legend>任务列表</legend>
        <div class="layui-field-box">
            <table class="layui-table site-table">
                <thead>
                <tr>
                   <!-- <th><input name="sortnum" type="checkbox" id="selected-all"></th>-->
                    <th>任务团队</th>
                    <th style="max-width: 120px;">商品链接</th>
                    <th>商品站点</th>
                    <th>站点状态</th>
                    <th>商品状态</th>
                    <th>任务状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="listcontent" class="layui-form">
                </tbody>
            </table>
        </div>
    </fieldset>
    <div class="admin-table-page">
        <div id="page" class="page">
        </div>
    </div>
</div>
<script id="demo" type="text/html">
    <tr>
        <td>{{d.t_name }}</td>
        <td style="max-width: 120px;text-overflow: ellipsis; overflow: hidden;"><a href="{{d.task_url}}" target="_blank">{{d.task_url}}</a> </td>
        <td>{{d.site_name}}</td>
        <td>{{# if(d.site_status == 2){ }} <span>禁止</span> {{# }else if(d.site_status == 1){ }} <span>开启</span> {{# } }}</td>
        <td>
            {{# if(d.task_status == 2){ }} <span>禁止</span> {{# }else if(d.task_status == 1){ }} <span>开启</span> {{# } }}
        </td>

        <td>
            {{# if(d.status == 2){ }} <span>结束</span> {{# }else if(d.status == 1){ }} <span>抢购排队中</span>{{# }else if(d.status == 4){ }} <span>正在抢购中</span> {{# }else if(d.status == 3){  }}<span>关闭</span> {{# } }}
        </td>
        <td>
            {{# if(d.status == 3){  }}
            <a  data="{{d.task_relid}}" class="layui-btn layui-btn-danger layui-btn-mini del"><i class="layui-icon">&#xe640;</i>{{d.status}}删除</a>
            {{# } }}
        </td>
    </tr>
</script>
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>

<script>
    var form,layer,$,laydate;
    layui.config({
        base: '__PUBLIC__/layui/modules/'
    });
    layui.use(['layer','icheck', 'form','laypage','laytpl','laydate'], function () {
        var laypage = layui.laypage,laytpl = layui.laytpl;
        laydate = layui.laydate;
        form = layui.form();
        $ = layui.jquery
        layer=layui.layer;
        var pagelistdate;
        var curr;
        form.render();
        laypage({
            cont: 'page',
            pages: {$page} //总页数
            ,
            groups: 5 //连续显示分页数
            ,

            jump: function(obj, first) {
                curr = obj.curr;
                listcontent.innerHTML='';
                $.ajax({
                    type: "GET",
                    url: "",
                    data: { p:curr},
                    async: false,
                    success: function(date){
                        if(date['code']==101) {
                            pagelistdate =date .data;
                            layui.each(date.data, function (k, v) {
                                var getTpl = demo.innerHTML;
                                laytpl(getTpl).render(v, function (html) {
                                    listcontent.innerHTML += html;
                                });
                            });
                        }
                    }
                });

                caozuo();
                ichecklist();
                form.render();
            }
        });
        //批量处理
        $('#batchdata').on('click', function() {
            var pidvalue = "";
            var i=0;
            $('input[name="sortnum"]:checked').each(function() {
                pidvalue += $(this).val() + ','
                i=1;
            });
            if(i==1){
                var url = "{:U('Task/batch')}";
                site="{$_GET['site']}";
                status="{$_GET['status']}";
                layer.confirm('确认任务批量操作吗', {
                    btn: ['删除','关闭','开启', '取消'] //可以无限个按钮
                    ,btn3: function(index, layero){
                        $.post(url, {type:1,ids:pidvalue,p:curr,site:site,status:status}, function(data){
                            if(data.code=="4001"){
                                layer.msg(data.msg,{icon: 5,time: 2000});
                            }else {
                               // layer.close(index);
                                layer.msg(data.msg,{icon: 6,time: 2000});
                                window.location.reload();

                            }
                        });
                    }
                }, function(index, layero){
                    $.post(url, {'type':3,'ids':pidvalue,'p':curr}, function(data){
                        if(data.code=="4001"){
                            layer.msg(data.msg,{icon: 5,time: 2000});
                        }else {

                            layer.msg(data.msg,{icon: 6,time: 2000});
                            window.location.reload();

                        }
                    });
                }, function(index, layero){
                    $.post(url, {'type':2,'ids':pidvalue,'p':curr}, function(data){
                        if(data.code=="4001"){
                            layer.msg(data.msg,{icon: 5,time: 2000});
                        }else {
                          //  layer.close(index);
                            layer.msg(data.msg,{icon: 6,time: 2000});
                            window.location.reload();
                        }
                    });
                });
            }else{
                layer.msg("请勾选",{icon: 5});
            }
        });
        function ichecklist() {
            $('.ichick').iCheck({
                checkboxClass: 'icheckbox_flat-green'
            });
            $('.site-table tbody tr').on('click', function (event) {
                var $this = $(this);
                var $input = $this.children('td').eq(0).find('.ichick');
                $input.on('ifChecked', function (e) {
                    $this.css('background-color', '#EEEEEE');
                });
                $input.on('ifUnchecked', function (e) {
                    $this.removeAttr('style');
                });
                $input.iCheck('toggle');
            }).find('.ichick').each(function () {
                var $this = $(this);
                $this.on('ifChecked', function (e) {
                    $this.parents('tr').css('background-color', '#EEEEEE');
                });
                $this.on('ifUnchecked', function (e) {
                    $this.parents('tr').removeAttr('style');
                });
            });
            $('#selected-all').on('ifChanged', function (event) {
                var $input = $('.site-table tbody tr td').find('input');
                $input.iCheck(event.currentTarget.checked ? 'check' : 'uncheck');
            });
        }

      /*  $('.add').click(function(){
            var url = "{:U('Team/createTeamTask')}";
            $.get(url,function(data){
                if(data.code == '4001'){
                    layer.msg(data.msg,{icon: 5});
                    return;
                }
                layer.open({
                    title:'创建团队任务',
                    type: 1,
                    skin: 'layui-layer-rim',
                    area: ['800px','500px'],
                    content: data
                });
            });
        });*/

        function caozuo(){
            $('.del').click(function () {
                var id = $(this).attr('data');
                var url = "{:U('Team/deletaskrel')}";
                layer.confirm('确定删除吗', {
                    icon: 3,
                    skin: 'layer-ext-moon',
                    btn: ['确认','取消']
                }, function(){
                    $.post(url,{keyid:id},function(data){
                        if(data.code=='4001'){
                            layer.msg(data.msg,{icon: 5});
                        }else{
                            layer.msg(data.msg, {
                                icon: 6,
                                time: 2000
                            }, function(){
                                window.location.reload();
                            });
                        }
                    });
                });
            });
        }
    });
</script>
</body>

</html>